package cn.fenglaicaimi.listener;

import cn.fenglaicaimi.base.domain.User;
import cn.fenglaicaimi.base.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Component
public class InitAdminListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private IUserService userService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        int count = this.userService.countUser();
        if (count == 0) {
            User user = new User();
            user.setUsername("admin");
            user.setPassword("1111");
            this.userService.save(user);
        }
    }
}
